﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FreeSql.DataAnnotations;
using CommonTools;

namespace shop.Model
{
    /// <summary> 运费核算配置 </summary>
    public class LogisticsFeeConfig : IDoc
    {
        [Column(IsPrimary =true, IsIdentity =true)]
        public int DocId { set; get; }


        [VarChar(20)]
        public string Number { get; set; }

        public DateTime? OccurDate { get; set; }

        [Column(StringLength = 50)]
        public string PreparedBy { get; set; }

        public DateTime? PreparedDate { get; set; }



        [Column(StringLength =200)]
        public string Remarks { set; get; }





        public byte? IsChecked { get; set; }

        [Column(StringLength = 30)]
        public string Checker { get; set; }

        public DateTime? CheckDate { get; set; }

        public bool? Isdel { get; set; }

        public DateTime? IsdelDate { get; set; }

        public DateTime? LastModifyTime { get; set; }


        [Column(IsIgnore = true)]
        public List<LogisticsFeeConfigItem> Items { set; get; } = new List<LogisticsFeeConfigItem>();



        [Column(IsIgnore = true)]
        public string SubTitle => string.IsNullOrEmpty(this.Number) ? "new" : this.Number+" "+ this.Remarks;

        [Column(IsIgnore = true)]
        public string DocFlag { get; set; } = DocFlagEnum.LogisticsFeeConfig;

        [Column(IsIgnore = true)]
        public DateTime? ReadTime { get; set; }

        [Column(IsIgnore = true)]
        public string RedText => this.IsChecked > 0 ? "已审核" : string.Empty;


        #region 事件: 保存 删除, 

        public event Action<IDoc> DocDeleted;
        public void OnDocDeleted() => this.DocDeleted?.Invoke(this);

        public event Action<IDoc> DocSaved;
        public void OnDocSaved() => this.DocSaved?.Invoke(this);

        #endregion


    }


    /// <summary>  </summary>
    public class LogisticsFeeConfigItem
    {
        [Column(IsPrimary = true, IsIdentity = true)]
        public int id { set; get; }


        public int DocId { set; get; }

        public int ItemId { get; set; }

        /// <summary> 报表分组 </summary>
        [Column(StringLength =100)]
        public string ReportGroup { set; get; }


        ///// <summary> 快递户头 </summary>
        //[Column(StringLength =100)]
        //public string LogiAccount { set; get; }


        ///// <summary> 是否区分仓库 </summary>
        //[Column(StringLength =100)]
        //public string Stock { set; get; }

        /// <summary> 快递户头 </summary>
        [Column(IsIdentity =true)]
        public string LogiAccountText { set; get; }


        /// <summary> 是否区分仓库 </summary>
        [Column(IsIdentity =true)]
        public string StockText { set; get; }

        ///// <summary> 是否区分快递公司 </summary>
        //public bool DistinguishCompany { set; get; }


        ///// <summary> 是否区分仓库 </summary>
        //public bool DistinguishStock { set; get; }


        /// <summary> 均摊金额 </summary>
        [Column(Precision =18, Scale =4)]
        public decimal ShareAmount { set; get; }


        /// <summary> 分配方式, 均摊, 金额加价, 数量加价, 重量加价, 自定义 </summary>
        [Column(StringLength =50)]
        public string Method { set; get; }


        /// <summary> 加价1 </summary>
        [Column(Precision = 18, Scale = 4)]
        public decimal AddPrice { set; get; }

        /// <summary> 重量范围最小值 </summary>
        [Column(Precision = 18, Scale = 4)]
        public decimal MinQty { set; get; }


        /// <summary> 重量范围最大值 </summary>
        [Column(Precision = 18, Scale = 4)]
        public decimal MaxQty { set; get; }


        ///// <summary> 加价2 </summary>
        //[Column(Precision = 18, Scale = 4)]
        //public decimal AddPrice2 { set; get; }

        ///// <summary> 加价范围最小值 </summary>
        //[Column(Precision = 18, Scale = 4)]
        //public decimal MinQty2 { set; get; }


        ///// <summary> 加价范围最大值 </summary>
        //[Column(Precision = 18, Scale = 4)]
        //public decimal MaxQty2 { set; get; }


        /// <summary> 筛选条件 </summary>
        public bool NeedFilter { set; get; }


        /// <summary>  </summary>
        [Column(StringLength =30)]
        public string FUser { set; get; }

        public DateTime FTime { get; set; }


        public bool Enable { get; set; }

        /// <summary> 有账单 无出库的 </summary>
        public bool NoOutstock { get; set; }


        public bool Isdel { get; set; }

        public LogisticsFeeConfigItem Clone()
        {
           return  this.MemberwiseClone() as LogisticsFeeConfigItem;
        }


        [Column(IsIgnore =true)]
        public List<LogiFeeConfigAcctItem> AcctItems { set; get; }

        [Column(IsIgnore = true)]
        public List<LogiFeeConfigStockItem> StockItems { set; get; }
    }



    public class LogiFeeConfigAcctItem
    {
        [Column(IsPrimary =true, IsIdentity =true)]
        public int id { set; get; }


        public int DocId { set; get; }

        [Column(StringLength =100)]
        public string LogiAcct { set; get; }
    }


    public class LogiFeeConfigStockItem
    {
        [Column(IsPrimary = true, IsIdentity = true)]
        public int id { set; get; }


        public int DocId { set; get; }

        [Column(StringLength = 100)]
        public string Stock { set; get; }
    }





}
